package com.chinasoft.book.app;

import com.chinasoft.book.mapper.BookMapper;
import com.chinasoft.book.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanInitMain {

    public static void main(String[] args) {
        ApplicationContext ioc = new ClassPathXmlApplicationContext("bean_init.xml");

        // 通过bean 构造方法
        BookMapper bookMapper = ioc.getBean("bookMapper", BookMapper.class);

        // 同 静态工厂 获取 bean
        BookService bookService = ioc.getBean("bookService", BookService.class);
        System.out.println(bookService);

        bookService.queryBook();

        // 通过实例工厂
        System.out.println("=============实例工厂========");
        BookMapper bookMapper2 = ioc.getBean("bookMapper2", BookMapper.class);
        bookMapper2.selectById(100);

        // 通过 FactoryBean对象获取 bean
        System.out.println("=============FactoryBean========");
        BookMapper bookMapper3 = ioc.getBean("bookMapper3", BookMapper.class);
        bookMapper3.selectById(100);

    }
}
